package tienmanh.gs.goldminer.sprite;

import org.andengine.entity.IEntity;
import org.andengine.entity.modifier.LoopEntityModifier;
import org.andengine.entity.modifier.PathModifier;
import org.andengine.entity.modifier.SequenceEntityModifier;
import org.andengine.entity.modifier.IEntityModifier.IEntityModifierListener;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.modifier.IModifier;

import android.R.array;

import tienmanh.gs.goldminer.base.BaseScene;
import tienmanh.gs.goldminer.manager.ResourcesManager;
import tienmanh.gs.goldminer.manager.SceneManager;
import tienmanh.gs.goldminer.scene.GameScene;
import tienmanh.gs.goldminer.util.Value;

public class Animal extends Object{
private  boolean isHuong;
private  int value;
private  boolean isCheckMouseRun;
private Sprite sprite;
private VertexBufferObjectManager vbom;
public boolean left , right;
public float start1,start2,end1,end2,speed;
	
	  @Override
	protected void onManagedUpdate(float pSecondsElapsed) {
		// TODO Auto-generated method stub
		super.onManagedUpdate(pSecondsElapsed);
		//Nếu đóng băng thì chuột dừng lại không thì thôi
		if(!GameScene.isFrzee && !isCheckMouseRun){
			if(end1 > start1)
			if(getX() > end1 || getX() < start1 ){
				speed = -speed;
				isHuong = !isHuong;
				if(isHuong) 
					animate(new long[] { 100L, 100L}, new int[]{0,1}, true);
				 else      
					animate(new long[] { 100L, 100L}, new int[]{2,3}, true);
			}
			if(end1 < start1){
				if(getX() < end1 || getX() > start1 ){
					speed = -speed;
					isHuong = !isHuong;
					if(!isHuong) 
						animate(new long[] { 100L, 100L}, new int[]{0,1}, true);
					 else     
						animate(new long[] { 100L, 100L}, new int[]{2,3}, true);
				}	
			}
			setPosition(getX()+speed, getY());
		}
	}
	@Override
	public void pullBackGold(float paramFloat1, float paramFloat2,
			float paramFloat3, float paramFloat4, boolean paramBoolean) {
		// TODO Auto-generated method stub
		super.pullBackGold(paramFloat1, paramFloat2, paramFloat3, paramFloat4,
				paramBoolean);
		stopAnimation();
    	unPigRun();
    	isCheckMouseRun = true;
	}
	private SequenceEntityModifier lemRun;
	public Animal(float pX, float pY, float pWidth, float pHeight,
			ITiledTextureRegion pTiledTextureRegion,
			VertexBufferObjectManager pVertexBufferObjectManager, int paramInt,
			float paramFloat5, String paramString) {
		super(pX, pY, pWidth, pHeight, pTiledTextureRegion, pVertexBufferObjectManager,
				paramInt, paramFloat5, paramString);
		// TODO Auto-generated constructor stub
		 isCheckMouseRun = false;
				 vbom = pVertexBufferObjectManager;
				 value = -1;
				 left = false;
				 right = false;
	}
	//huong = true phai sang trai
	 public void pigRun(final float paramFloat1, final float paramFloat2, final float paramFloat3, final float paramFloat4, final float paramFloat5, final boolean huong)
	  {
		 end1 = paramFloat3;
		 end2 = paramFloat4;
		 speed = paramFloat5;
		 start1 = paramFloat1;
		 start2 = paramFloat2;
		 isHuong = huong;
		 if(huong) 
			 animate(new long[] { 100L, 100L}, new int[]{0,1}, true);
		 else      
			 animate(new long[] { 100L, 100L}, new int[]{2,3}, true);
		 
	  }
	 public void unPigRun()
	  {
	    unregisterEntityModifier(this.lemRun);
	  }
	 

}
